package com.vineetmanohar.nitrogen;

/**
 * Model represents primitive data
 * 
 * @author vineetmanohar
 */
public class PrimitiveModel implements WritableModel {
	private String value;

	public PrimitiveModel(String value) {
		this.value = value;
	}

	public String getValueAsString() {
		return value;
	}

	public boolean isPrimitive() {
		return true;
	}

	public ObjectModel getObjectModel() {
		return null;
	}

	@Override
	public String toString() {
		return getValueAsString();
	}

	public boolean isObject() {
		return false;
	}

	public boolean isArray() {
		return false;
	}

	public ArrayModel getArrayModel() {
		return null;
	}

	public PrimitiveModel getPrimitive() {
		return this;
	}

	private Model parent;

	public Model getParent() {
		return parent;
	}

	public void setParent(Model parent) {
		this.parent = parent;
	}

	private String modelName;

	public String getModelName() {
		if (parent != null && parent.isArray()) {
			return parent.getArrayModel().getModelName();
		}

		return modelName;
	}

	public void setModelName(String modelName) {
		this.modelName = modelName;
	}

	public int getDepth() {
		return ModelUtils.getDepth(this);
	}
}
